package de.tabuma.pm.project.logik;

import de.tabuma.pm.project.entity.Project;
import de.tabuma.customer.entity.*;
import de.tabuma.customer.logik.CustomerFacade;
import de.tabuma.pm.logik.*;

import java.util.*;
import java.util.logging.*;

/**
  * @author $Author: $
  * @version $Revision: $
  * @since $Date: $
 */
public class ProjectFacade {

    private static final Logger log = Logger.getLogger(ProjectFacade.class.getName());

    public static int create(Project project, String user) {
        return (int) PMF.doCreate(project,user);
    }

    public static Project get(int ID) {
        return PMF.get(ID, new Project());
    }

    public static List<Project> get(String keys[], String values[]) {
        return PMF.get(keys, values, new Project());
    }

    public static void update(Project project, String user) {
        PMF.doUpdate(project, user);
    }

    public static void remove(int projectID, String user) {
        Project project = get(projectID);
        PMF.doRemove(project,user);
    }

    public static List<Project> getList(String user) {
        List<Customer> cList = CustomerFacade.getCustomer(user);
        List<Project> pList = new ArrayList<Project>();
        for(int i=0;i<cList.size();i++) {
            Customer customer = cList.get(i);
            String keys[] = new String[1];
            keys[0] = "customerId";
            String values[] = new String[1];
            values[0] = ""+customer.getId();
            List<Project> pList1 = get(keys,values);
            pList.addAll(pList1);
        }
        return pList;
    }

}
